#include "Waypoint.h"

Waypoint::Waypoint(string cacheName, string cacheDescription, string latitude, string longitude)
{
	this->cacheName = cacheName;
	this->cacheDescription = cacheDescription;
	this->latitude = latitude;
	this->longitude = longitude;
}

Waypoint::~Waypoint()
{
}

string& Waypoint::replaceAll(string& context, const string& from, const string& to) const
{
	size_t lookHere = 0;
	size_t foundHere;
	while ((foundHere = context.find(from, lookHere)) != string::npos)
	{
		context.replace(foundHere, from.size(), to);
		lookHere = foundHere + to.size();
	}

	return context;
}

string Waypoint::getCacheDesc(bool escapeQuotes = false) const
{
	if (escapeQuotes == false)
		return cacheDescription;

	string fixedDescription(cacheDescription);

	//replaceAll(fixedDescription, string("'"), string("\'"));
	std::replace(fixedDescription.begin(), fixedDescription.end(), '\'', '_');

	return fixedDescription;
}
